package cn.taskservice.common.utils.result;

import cn.taskservice.common.enums.ResultCode;
import cn.taskservice.common.vo.Result;

import java.time.LocalDateTime;

public class ResultUtil {

    public static <T> Result<T> success() {
        return new Result<>(ResultCode.SUCCESS, null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultCode.SUCCESS, data);
    }

    public static <T> Result<T> success(String message, T data) {
        Result<T> result = new Result<>(ResultCode.SUCCESS, data);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> failure(String message) {
        Result<T> result = new Result<>(ResultCode.FAIL, null);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> failure(ResultCode resultCode) {
        return new Result<>(resultCode, null);
    }

    public static <T> Result<T> failure(int code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        result.setTimestamp(LocalDateTime.now());
        return result;
    }
}
